#include <iostream>

using namespace std;
const int N = 2e5 + 10;
typedef long long LL;
LL a[N], b[N];
LL n, m;
bool check(LL x)
{
	LL cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		if (a[i] + b[i] < x) return false;

		if (a[i] < x)
			cnt += (x - a[i]);
		if (cnt > m) return false;
	}
	return true;
}
int main()
{
	cin >> n >> m;
	LL l = 0, r = 0;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++)
	{
		cin >> b[i];
		r = max(r, b[i] + a[i]);
	}
	while (l < r)
	{
		LL mid = (l + r + 1) / 2;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	cout << l << endl;
	return 0;
}